import logging

# 获取实例
logger = logging.getLogger(__name__)
# 设置日志级别
logger.setLevel(logging.DEBUG)


# 设置日志格式
common_formatter = logging.Formatter('%(name)s--%(levelno)s--%(lineno)d--%(message)s--%(asctime)s')


# 设置日志处理句柄
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
stream_handler.setFormatter(common_formatter)

# 设置文件处理句柄
file_handler = logging.FileHandler(f"{__name__}.log", encoding="utf8")
file_handler.setLevel(logging.WARNING)
file_handler.setFormatter(common_formatter)


# 添加流句柄
logger.addHandler(stream_handler)
logger.addHandler(file_handler)


# 输出
logger.error("出错了")





